#set( $symbol_pound = '#' )
#set( $symbol_dollar = '$' )
#set( $symbol_escape = '\' )
package ${package}.service.common;

/**
 * Created by well on 2017/11/18.
 */
public class BizResultHelper {

    public static BizResult newSuccess() {
        BizResult bizResult = new BizResult();
        ErrorMessageHandler bean = SpringBeanUtil.getBean(ErrorMessageHandler.class);
        if (bean == null) {
            throw new IllegalArgumentException("无法找到bean:ErrorMessageHandler");
        }
        String message = bean.getMessage(ErrorCode.SUCCESS.getCode());
        bizResult.code = ErrorCode.SUCCESS.getCode();
        bizResult.msg = message;
        bizResult.success = true;
        return bizResult;
    }


    public static BizResult newFail(ErrorCode errorCode) {
        if (errorCode == null) {
            throw new IllegalArgumentException("errorCode不能为空");
        }
        BizResult bizResult = new BizResult();
        ErrorMessageHandler bean = SpringBeanUtil.getBean(ErrorMessageHandler.class);
        if (bean == null) {
            throw new IllegalArgumentException("无法找到bean:ErrorMessageHandler");
        }
        String message = bean.getMessage(errorCode.getCode());
        bizResult.code = errorCode.getCode();
        bizResult.msg = message;
        return bizResult;
    }
}
